package com.leetcode.leetcode1;

/**
 * @program: 整数转罗马数字
 * @author: luhd
 * @create: 2021-08-22
 */
public class Practice12 {
    public static void main(String[] args) {
        int num = 58;
        String s = intToRoman(num);
        System.out.println(s);
    }
    public static String intToRoman(int num) {
        int values[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String reps[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
        String s="";
        for (int i = 0; i < values.length; i++)
        {
            while(num>=values[i]){
                num -=values[i];
                s = s+reps[i];
            }
        }
        return s;
    }
}
